/**
 * creation: 14-mrt-2008
 */
package org.jfonia.connect;

import java.util.List;

/**
 * @author wijnand.schepens@gmail.com
 *
 */
public class ListElement<T> extends BasicNode implements MutableValue<T>
{
	protected List<T> list;
	protected Value<Integer> index;

	public ListElement(List<T> list, Value<Integer> index)
	{
		super();
		this.list = list;
		this.index = index;
		
		index.addCallTarget(this);	// TODO: not necesarily...
	}	
	

	public void set(T newValue)
	{
		list.set(index.get(), newValue);
	}
	
	public T get()
	{
		return list.get(index.get());
	}
	
	public boolean isIndexValid()
	{
		return index.get() >= 0 && index.get() < list.size();
	}
}
